import { useAuth } from '@/stores/auth'
export const permission = {
  mounted(el:any, binding:any) {
    const permissionArr = useAuth().userInfo.role_ids
    const { value } = binding
    if (value && value instanceof Array) {
      if (value.length > 0) {
        const permissionRoles = value

        const hasPermission = permissionArr.some(role => {
          return permissionRoles.includes(role)
        })

        if (!hasPermission) {
          el.parentNode && el.parentNode.removeChild(el)
        }
      }
    } else {
      throw new Error(`need roles! Like v-permission="['admin','editor']"`)
    }
  },

}
